#!/usr/bin/env python

from urlparse import urlparse

from google.appengine.ext import db
from google.appengine.ext.db import djangoforms


# ---=== Model class ===---
class Category(db.Model):
    name    = db.StringProperty()
    sort    = db.IntegerProperty(default=0)
    
    
class Site(db.Model):
    cat     = db.ReferenceProperty(Category)
    title   = db.StringProperty()
    url     = db.LinkProperty()
    sort    = db.IntegerProperty(default=0)
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)
    
    def favicon(self):
        urlinfo = urlparse(self.url)
        return urlinfo[0] + '://' + urlinfo[1] + '/favicon.ico'

class CategoryForm(djangoforms.ModelForm):
    class Meta:
        model = Category

class SiteForm(djangoforms.ModelForm):
    class Meta:
        model = Site